/**
 * 
 */
package gui.pop;

import gui.dialog.CommChatRoomDialog;
import gui.tab.ChatCompositeTab;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.example.www.communication.ChatService.ChatRoom;

/**
 * Menu PopUp para Utilizar en la lista de chat rooms activos.
 * 
 * @author lito
 */
public class ChatPopUpMenu {
	private ChatRoom			chatRoom;
	private ChatCompositeTab	father;
	
	private Menu				swtmPopup;
	private MenuItem			swtmiEnterChatRoom;
	
	public ChatPopUpMenu(Decorations parent, int style) {
		swtmPopup = new Menu(parent, style);
		parent.getShell().setMenu(swtmPopup);
		
		swtmiEnterChatRoom = new MenuItem(swtmPopup, SWT.PUSH);
		swtmiEnterChatRoom.setText("Enter");
		swtmiEnterChatRoom.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent evt) {
				enterChatRoomMenuItemWidgetSelected(evt);
			}
		});
		swtmiEnterChatRoom.setImage(new Image(Display.getCurrent(),
				"resource/tango-icon-theme-0.8.90/16x16/actions/go-next.png"));
	}
	
	public void setBoss(Control boss) {
		boss.setMenu(swtmPopup);
	}
	
	public void setChatRoom(ChatRoom chatRoom) {
		this.chatRoom = chatRoom;
	}
	
	private void enterChatRoomMenuItemWidgetSelected(SelectionEvent evt) {
		CommChatRoomDialog crd = new CommChatRoomDialog(this.swtmPopup.getShell(),
				this.swtmPopup.getShell().getStyle());
		crd.setChatRoom(chatRoom);
		crd.setFather(father);
		father.addEnteredChatRoom(crd);
		crd.open();
	}
	
	/**
	 * @param father
	 *        the father to set
	 */
	public final void setFather(ChatCompositeTab father) {
		this.father = father;
	}
	
}
